package top.as.sean.api.controller.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.as.sean.biz.system.IPost;
import top.as.sean.common.response.Result;
import top.as.sean.dao.dto.system.DeleteDto;
import top.as.sean.dao.dto.system.PostAdd;
import top.as.sean.dao.dto.system.PostEdit;
import top.as.sean.dao.dto.system.PostPage;
import top.as.sean.dao.entity.pojo.system.Post;
import top.as.sean.dao.vo.system.PostVo;

import java.util.List;

/**
 * 岗位信息
 *
 * @author: ArchieSean
 * @create: 2022/11/24
 */
@RestController
@RequestMapping("post")
@RequiredArgsConstructor
public class PostController {

    private final IPost iPost;

    /**
     * 查询所有可用岗位
     * @return list
     */
    @GetMapping("all")
    public Result<List<Post>> getAll() {
        return Result.success(iPost.getAll());
    }

    /**
     * 删除职位信息
     *
     * @return boolean
     */
    @PostMapping("delete")
    public Result<Boolean> deleteBatch(@RequestBody @Validated DeleteDto dto) {
        return Result.success(iPost.deleteBatch(dto.getIds()));
    }

    /**
     * 新增职位信息
     *
     * @param dto 入参
     * @return boolean
     */
    @PostMapping("add")
    public Result<Boolean> addPost(@Validated @RequestBody PostAdd dto) {
        return Result.success(iPost.addPost(dto));
    }

    /**
     * 分页查询职位信息
     *
     * @param dto 入参
     * @return page
     */
    @GetMapping("page")
    public Result<Page<PostVo>> getPage(@Validated @ModelAttribute PostPage dto) {
        return Result.success(iPost.getPage(dto));
    }

    /**
     * 编辑职位信息
     *
     * @param dto 入参
     * @return boolean
     */
    @PutMapping("edit")
    public Result<Boolean> editPost(@Validated @RequestBody PostEdit dto) {
        return Result.success(iPost.editPost(dto));
    }
}
